package com.example.leo.mycharmingstudent.a0911.launchmode;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;

import com.example.leo.mycharmingstudent.R;
import com.example.leo.mycharmingstudent.a0905.ToastUtil;

public class StandardActivity extends BaseActivity {

    //启动standard模式Activity 按钮
    private Button btnStandard;
    //启动singleTop模式Activity 按钮
    private Button btnSingleTop;
    //启动singleTask模式Activity 按钮
    private Button btnSingleTask;
    //启动singleInstance模式Activity 按钮
    private Button btnSingleInstance;
    private Button btnBackResult;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_standard);

        findViews();
        initData();
        initEvent();
    }

    private void findViews() {
        btnStandard = findViewById(R.id.btn_start_standard_activity_standard);
        btnSingleTop = findViewById(R.id.btn_start_single_top_activity_standard);
        btnSingleTask = findViewById(R.id.btn_start_single_task_activity_standard);
        btnSingleInstance = findViewById(R.id.btn_start_single_instance_activity_standard);
        btnBackResult = findViewById(R.id.btn_back_result_activity_standard);
    }

    private void initData() {
        /*Intent intent = new Intent();
        Bundle bundle = new Bundle();
        bundle.putString("name", getClass().getSimpleName());
        intent.putExtras(bundle);
        intent.setClass(this, SingleTopActivity.class);
        startActivity(intent);*/
    }

    private void initEvent() {
        btnStandard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(StandardActivity.this,
                        StandardActivity.class));
            }
        });
        btnSingleTop.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(StandardActivity.this,
                        SingleTopActivity.class));
            }
        });
        btnSingleTask.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(StandardActivity.this,
                        SingleTaskActivity.class));
            }
        });
        btnSingleInstance.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(StandardActivity.this,
                        SingleInstanceActivity.class));
            }
        });
        btnBackResult.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivityForResult(
                        new Intent(StandardActivity.this, SingleTopActivity.class),
                        1000);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1000) {
            if (resultCode == RESULT_OK) {
                if (data != null) {
                    Bundle bundle = data.getExtras();
                    if (bundle != null) {
                        String info = bundle.getString("info");
                        ToastUtil.showToast(this, info);
                    }
                }
            }
        }
    }
}
